{extend name="base" /}
{block name="content"}
<script src="__STATIC__/public/My97DatePicker/WdatePicker.js"></script>
<div class="g-main">
    <div class="m-main-title">
        <div class="m-container-fluid">
            <a href="{:url('index/welcome')}"><i class="icon icon-home"></i>首页</a>
            <span class="icon-angle-right"></span>
            <span>商城</span>
            <span class="icon-angle-right"></span>
            <span>活动管理</span>
            <span class="icon-angle-right"></span>
            <span>{$info ? '编辑' : '添加'}活动商品</span>
            <a class="u-flush"><i class="icon-repeat"></i></a>
        </div>
    </div>
    <div class="m-main-content">
        <div class="m-container">
            <div class="m-form">
                <form class="layui-form" id="j_form">
                    <table class="m-table">
                        <thead>
                        <tr>
                            <th colspan="2">{$info ? '编辑' : '添加'}活动</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td width="15%"><label for="title">活动名称<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="title" id="title" placeholder="请输入活动名称" value="{$info.title}" /></td>
                        </tr>


                        <tr>
                            <td width="15%"><label for="describe">活动描述</label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="describe" id="describe" placeholder="请输入活动描述" value="{$info.describe}" /></td>
                        </tr>

						<tr>
							<td><label for="">活动类型<em>*</em></label></td>
							<td>
								<div class="lay-select">
									<select name="act_type">
										<option value="0">请选择活动类型</option>
										<option value="1"{if condition="$info['act_type'] eq 1"} selected{/if}>拼团</option>
										<option value="2"{if condition="$info['act_type'] eq 2"} selected{/if}>限时抢购</option>
									</select>
								</div>
							</td>
						</tr>

                        <tr >
                            <td><label for="">商品缩略图</label></td>
                            <td>
                                <button type="button" class="layui-btn u-upload-pic" data-name="image_uri"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                                <div class="m-pic">
                                    <ul>
                                        {:attach_html($info.image_uri, 'image_uri')}
                                    </ul>
                                </div>
                            </td>
                        </tr>

                        <tr>
                            <td width="15%"><label for="startdt">活动有效期</label></td>
                            <td><input type="text" name="startdt" class="u-ipt u-ipt-long" id="startdt" placeholder="开始时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="{$info.startdt ? date('Y-m-d H:i:s',$info.startdt) : date('Y-m-d', time())}" readonly="">-<input type="text" name="enddt" class="u-ipt u-ipt-long" id="enddt" placeholder="结束时间" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" value="{$info.enddt ? date('Y-m-d H:i:s',$info.enddt) : date('Y-m-d', time())}" readonly=""></td>
                        </tr>
<!--                        <tr>-->
<!--                            <td width="15%"><label for="enddt">结束时间</label></td>-->
<!--                            <td></td>-->
<!--                        </tr>-->
                        <tr>
                            <td><label for="">是否上架</label></td>
                            <td><div class="lay-checked"><input type="checkbox" name="status" value="1" title="是" lay-skin="primary"{$info.status ? ' checked' : ''} /></div></td>
                        </tr>
                        <tr>
                            <td><label for="">是否推荐首页</label></td>
                            <td><div class="lay-checked"><input type="checkbox" name="is_home" value="1" title="是" lay-skin="primary"{$info.is_home ? ' checked' : ''} /></div></td>
                        </tr>
                        <tr>
                            <td width="15%"><label for="list_order">排序<em>*</em></label></td>
                            <td><input type="text" class="u-ipt u-ipt-longer" name="list_order" id="list_order" placeholder="请输入活动排序" value="{$info.list_order}" /></td>
                        </tr>
                        <input type="hidden" value="{$info.register_time ? $info.register_time : time()}" name="register_time" id="register_time"/>
                    </table>
                    <div class="m-form-btn"><input type="hidden" name="id" value="{$info.id}"><button id="j_btn" class="u-btn">确定提交</button></div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="extrajs"}
<script src="__STATIC__/public/js/jquery-ui.min.js"></script>
{include file="public:upload"/}
<script>
    layui.use(['layer', 'form', 'upload'], function() {
        $('.u-edit').on('click', function () {
            var $input = $(this).parent().prev();
            var $that = $(this);
            var key = $that.attr('data-key');
            var id = $that.attr('data-id');
            var title = key == 'points' ? '搜索商品名' : '搜索商品名';

            layer.open({
                type: 1,
                title: title,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '400px'], //宽高
                content: '<div class="m-edit-form"><input type="text" id="name" class="u-ipt name"><p>直接输入要搜索的商品名</p><input type="button" class="u-btn" id="sousuo"  value="搜索" /></div>'
            });
        });
        /*点击搜索  搜索商品名*/
        $('body').on('click', '#sousuo', function () {
            var html = '';
            $('.m-edit-form p:nth-of-type(2)').remove();
            $('.m-edit-form input:nth-of-type(3)').remove();
            var name = $(this).parent('.m-edit-form').find('.name').val();
            $.post('{:url("goods")}', {name:name}, function (ret) {
                if (ret) {
                    var obj = eval(ret);
                    html += "<p>";
                    for(var i=0; i<obj.length; i++)
                    {
                        var id = obj[i].id;
                        var goodsname = obj[i].goods_name;
                        html += '<input type="radio" name="a" value="' + goodsname + '" data="' + id + '"/>' + goodsname     ;
                    }
                    html += "</p><input type=\"button\" class=\"u-btn\" id=\"tijiao\"  value=\"提交\" />";
                    $('.m-edit-form').append(html);
                }
            }, 'json');
        });
        /*点击弹框的提交*/
        $('body').on('click', '#tijiao', function () {
            $("input[name='a']:checked").each(function(){
                $('#goods_id1').val($(this).val());
                $('#goods_id').val($(this).attr('data'));
            })
            layer.closeAll();
        });
    })
</script>
{/block}